package com.hdd.biz.painting.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hdd.biz.painting.dto.*;
import com.hdd.biz.painting.entity.MaterialKind;
import com.hdd.biz.painting.mapper.MaterialKindMapper;
import com.hdd.biz.painting.service.MaterialKindService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdd.dto.SuperResponse;
import com.hdd.utils.IdUtils;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 裱框背景分类表 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-03-09
 */
@Service
public class MaterialKindServiceImpl extends ServiceImpl<MaterialKindMapper, MaterialKind> implements MaterialKindService {


    @Override
    public SuperResponse materialKindList(MaterialKindListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<MaterialKind> wrapper = new QueryWrapper();
        Page<MaterialKind> pages = new Page<>(request.getPageNo(),request.getPageSize());
        wrapper.eq("cover_type",1);
        wrapper.eq("del_flag",0);
        wrapper.eq("type","2");
        if(!StringUtil.isNullOrEmpty(request.getName())){
            wrapper.like("name",request.getName());
        }
        IPage<MaterialKind> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<MaterialKind> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }


    @Override
    public SuperResponse backdropList(BackdropListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<MaterialKind> wrapper = new QueryWrapper();
        wrapper.eq("cover_type",1);
        wrapper.eq("type","3");
        wrapper.eq("del_flag",0);
        if(!StringUtil.isNullOrEmpty(request.getName())){
            wrapper.like("name",request.getName());
        }
        Page<MaterialKind> pages = new Page<>(request.getPageNo(),request.getPageSize());
        IPage<MaterialKind> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<MaterialKind> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }



    @Override
    public SuperResponse colorList(ColorListRequest request) {
        SuperResponse response = new SuperResponse();
        QueryWrapper<MaterialKind> wrapper = new QueryWrapper();
        wrapper.eq("cover_type",2);
        if(!StringUtil.isNullOrEmpty(request.getName())){
            wrapper.like("name",request.getName());
        }
        wrapper.eq("del_flag",0);
        Page<MaterialKind> pages = new Page<>(request.getPageNo(),request.getPageSize());
        IPage<MaterialKind> mapIPage = baseMapper.selectPage(pages, wrapper);
        List<MaterialKind> agents = mapIPage.getRecords();
        response.setItems(agents);
        response.setTotals(pages.getTotal());
        return response;
    }

    @Override
    public SuperResponse materialAdd(MaterialKindInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(IdUtils.getUUID());
        materialKind.setName(request.getName());
        materialKind.setCoverUrl(request.getCoverUrl());
        materialKind.setCoverType(1);
        materialKind.setDelFlag(0);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setType(2);
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.insert(materialKind);
        return response;
    }

    @Override
    public SuperResponse materialUpdate(MaterialKindInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setName(request.getName());
        materialKind.setCoverUrl(request.getCoverUrl());
        materialKind.setCoverType(1);
        materialKind.setDelFlag(0);
        materialKind.setType(2);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.updateById(materialKind);
        return response;
    }


    @Override
    public SuperResponse materialdel(MaterialKindRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setDelFlag(1);
        baseMapper.updateById(materialKind);
        return response;
    }

    @Override
    public SuperResponse backdropAdd(BackdropInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(IdUtils.getUUID());
        materialKind.setName(request.getName());
        materialKind.setCoverUrl(request.getCoverUrl());
        materialKind.setCoverType(1);
        materialKind.setDelFlag(0);
        materialKind.setType(3);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.insert(materialKind);
        return response;
    }

    @Override
    public SuperResponse backdropDel(MaterialKindRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setDelFlag(1);
        baseMapper.updateById(materialKind);
        return response;
    }


    @Override
    public SuperResponse backdropUpdate(BackdropInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setName(request.getName());
        materialKind.setCoverUrl(request.getCoverUrl());
        materialKind.setCoverType(1);
        materialKind.setDelFlag(0);
        materialKind.setType(3);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.updateById(materialKind);
        return response;
    }


    @Override
    public SuperResponse colorAdd(ColorInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(IdUtils.getUUID());
        materialKind.setName(request.getName());
        materialKind.setCoverColor(request.getCoverColor());
        materialKind.setCoverType(2);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setDelFlag(0);
        materialKind.setType(3);
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.insert(materialKind);
        return response;
    }

    @Override
    public SuperResponse colorDel(MaterialKindRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setDelFlag(1);
        baseMapper.updateById(materialKind);
        return response;
    }

    @Override
    public SuperResponse colorUpdate(ColorInfoRequest request) {
        SuperResponse response = new SuperResponse();
        MaterialKind materialKind = new  MaterialKind();
        materialKind.setId(request.getId());
        materialKind.setName(request.getName());
        materialKind.setCoverColor(request.getCoverColor());
        materialKind.setCoverType(2);
        materialKind.setDelFlag(0);
        materialKind.setType(3);
        materialKind.setRemarks(request.getRemarks());
        materialKind.setSort(request.getSort());
        materialKind.setDescription(request.getDescription());
        baseMapper.updateById(materialKind);
        return response;
    }

    @Override
    public SuperResponse materialKindInfo(MaterialKindRequest request) {
        SuperResponse response = new SuperResponse();
        response.setItem(baseMapper.selectById(request.getId()));
        return response;
    }

}
